package org.chen.common.utils;

import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

@Component
public class DateUtils {
    private static final ZoneId CHINA_ZONE = ZoneId.of("Asia/Shanghai");

    public static Date getCurrentDate() {
        return Date.from(LocalDate.now(CHINA_ZONE).atStartOfDay(CHINA_ZONE).toInstant());
    }

    public static Date getCurrentDateTime() {
        return Date.from(LocalDateTime.now(CHINA_ZONE).atZone(CHINA_ZONE).toInstant());
    }

    public static Date getTodayStartTime() {
        LocalDateTime todayStart = LocalDate.now(CHINA_ZONE).atStartOfDay();
        return Date.from(todayStart.atZone(CHINA_ZONE).toInstant());
    }

    public static Date getTodayEndTime() {
        LocalDateTime todayEnd = LocalDate.now(CHINA_ZONE).atTime(23, 59, 59);
        return Date.from(todayEnd.atZone(CHINA_ZONE).toInstant());
    }

    public static boolean isToday(Date date) {
        LocalDate givenDate = date.toInstant().atZone(CHINA_ZONE).toLocalDate();
        LocalDate today = LocalDate.now(CHINA_ZONE);
        return givenDate.equals(today);
    }
}
